﻿Public Class frmLocChungTu
    Private fCall As frmQLChungTu = Nothing
    Public _danhMucChon As String = ""
    Private ctrlDanhMuc As New CDanhMucController(_nganSachDataContext)
    Private Sub HienThiDieuKienLoc()
        If (fCall IsNot Nothing) Then
            'If (fCall._danhMucLoc <> "") Then
            '    _danhMucChon = fCall._danhMucLoc
            '    txtDanhMuc.Text = ctrlDanhMuc.GetShortPath(_danhMucChon)
            'End If
            If (fCall._tuNgay <> Date.MinValue) Then
                txtNgayCTTu.Text = fCall._tuNgay.ToString("dd/MM/yyyy")
            End If
            If (fCall._denNgay <> Date.MinValue) Then
                txtNgayCTDen.Text = fCall._denNgay.ToString("dd/MM/yyyy")
            End If
            If (fCall._soCT <> "") Then
                txtSoCT.Text = fCall._soCT
            End If
            If (fCall._dienGiai <> "") Then
                txtDienGiai.Text = fCall._dienGiai
            End If
            If (fCall._soTienTu <> Decimal.MinValue) Then
                txtSoTienTu.Text = fCall._soTienTu.ToString("#,##0.##")
            End If
            If (fCall._soTienDen <> Decimal.MinValue) Then
                txtSoTienDen.Text = fCall._soTienDen.ToString("#,##0.##")
            End If
        End If
    End Sub

    Private Sub frmLocChungTu_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        HienThiDieuKienLoc()
        txtDanhMuc.Focus()
    End Sub

    Private Sub LinkLabel1_LinkClicked(ByVal sender As System.Object, ByVal e As System.Windows.Forms.LinkLabelLinkClickedEventArgs) Handles btChonDanhMuc.LinkClicked
        '_danhMucChon = ""
        'Dim frm As New frmQLDanhMuc(Me)
        'frm.ShowDialog()
        'If (_danhMucChon <> "") Then
        '    txtDanhMuc.Text = ctrlDanhMuc.GetShortPath(_danhMucChon)
        'End If
    End Sub

    Private Sub txtSoTien_Leave(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtSoTienTu.Leave, txtSoTienDen.Leave
        Dim txt As TextBox = sender
        If (CUtilities.CheckNumberInTextbox(txt) = True) Then
            CUtilities.FormatNumber(txt)
        End If
    End Sub

    Private Sub txtNgayCTTu_Leave(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtNgayCTTu.Leave, txtNgayCTDen.Leave
        Dim txt As MaskedTextBox = sender
        CUtilities.CheckDateInMaskTextBox(txt, "ngày/tháng/năm")
    End Sub

    Private Sub btLoc_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btLoc.Click
        Dim _tuNgay As Date = Date.MinValue
        Dim _denNgay As Date = Date.MinValue
        Dim _isNo As Integer = 0 ' 0: chọn hết, 1: IsNo=true, 2: IsNo= false
        Dim _soTienTu As Decimal = Decimal.MinValue
        Dim _soTienDen As Decimal = Decimal.MinValue
        If (txtNgayCTTu.Text <> "  /  /") Then
            _tuNgay = CUtilities.GetDateFromString(txtNgayCTTu.Text, "ngày/tháng/năm")
        End If
        If (txtNgayCTDen.Text <> "  /  /") Then
            _denNgay = CUtilities.GetDateFromString(txtNgayCTDen.Text, "ngày/tháng/năm")
        End If
        If (txtSoTienTu.Text <> "" And txtSoTienTu.Text <> "0") Then
            _soTienTu = Decimal.Parse(txtSoTienTu.Text)
        End If
        If (txtSoTienDen.Text <> "" And txtSoTienDen.Text <> "0") Then
            _soTienDen = Decimal.Parse(txtSoTienDen.Text)
        End If
        fCall.SetDieuKienLoc(_tuNgay, _denNgay, chkDanhMucNull.Checked, _danhMucChon, txtSoCT.Text, txtDienGiai.Text, _soTienTu, _soTienDen)
        Me.Close()
    End Sub

    Private Sub chkDanhMucNull_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles chkDanhMucNull.CheckedChanged
        If (chkDanhMucNull.Checked) Then
            txtDanhMuc.Text = ""
            _danhMucChon = ""
            txtDanhMuc.ReadOnly = True
            btChonDanhMuc.Enabled = False
        Else
            txtDanhMuc.ReadOnly = False
            btChonDanhMuc.Enabled = True
        End If
    End Sub

    Public Sub New()

        ' This call is required by the designer.
        InitializeComponent()

        ' Add any initialization after the InitializeComponent() call.

    End Sub
    Public Sub New(ByVal frm As frmQLChungTu)

        ' This call is required by the designer.
        InitializeComponent()

        ' Add any initialization after the InitializeComponent() call.
        fCall = frm
    End Sub

    Private Sub btClose_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btClose.Click
        Me.Close()
    End Sub

    Private Sub txtDanhMuc_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtDanhMuc.TextChanged

    End Sub
End Class